package thread;


class MyThread2 extends Thread{
    @Override
    public void run() {
        while (true){
            System.out.println("hello thread");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
public class ThreadDemo2 {
    public static void main(String[] args) throws InterruptedException {
        MyThread2 t1 = new MyThread2();
        t1.start();
        //在调用start之后，创建线程，自此兵分两路
        //一边继续main函数，另一路调用run方法
        //所以打印出来的循环为交替出现

        while (true){
            System.out.println("hello main");
            Thread.sleep(1000);
        }
    }
}
